<style lang="scss" scoped>
.error-page-box{
    position: relative;
    width: 100%;
    height: 100%;
    background: url('~@/assets/404-img.png') no-repeat center bottom;
    background-size: 100%;
}
</style>
<template>
    <div class="error-page-box">
        <div class="error-page-btn-box">
<!--            <p class="tips"><span>{{ times }}</span>秒后返回上一页</p>-->
            <template v-if="user">
                <p><el-button @click="logout" entity class="accent">退出登录</el-button></p>
            </template>
            <p><el-button @click="goHome" entity class="accent toIndex">返回首页</el-button></p>
            <p><el-button @click="goBack" entity class="accent">返回上一页</el-button></p>
        </div>
    </div>
</template>

<script lang="ts">
import Vue from "vue";
import { Component } from "vue-property-decorator";
import { State } from 'vuex-class';
@Component
export default class ErrorPage404 extends Vue {
    @State(state => state.user.userInfo) user: any;

    times = 3
    timer: any = null

    created() {
        this.timer = setInterval(() => {
            if (this.times > 0) {
                this.times--;
            } else {
                clearInterval(this.timer);
                this.goBack();
            }
        }, 1000);
    }

    async logout() {
        clearInterval(this.timer);
        await this.$store.dispatch("logout");
        this.$nextTick(() => {
            window.location.href = "/";
            // this.$router.replace({ path: '/auth/login' });
        });
    }

    goHome() {
        clearInterval(this.timer);
        this.$router.replace({ name: 'home' });
    }

    goBack() {
        clearInterval(this.timer);
        this.$router.back();
    }

    beforeDestroy() {
        clearInterval(this.timer);
    }
}
</script>
<style lang="scss" scoped>
    .error-page-btn-box {
        position: absolute;
        bottom: 88px;
        left: 50%;
        transform: translate(-50%, 0);
        .tips {
            text-align: center;
            margin: 0 0 20px 0;
            font-size: 16px;

            span {
                color: #ff4747;
                font-weight: 500;
                font-size: 24px;
            }
        }
        p {
            margin: 0;
        }
        .accent {
            border: 2px solid #FFFFFF;
            border-radius: 20px;
            height: 40px;
            font-size: 18px;
            font-family: "PingFang SC Medium";
            color: #FFFFFF;
            background: transparent;
            margin-top: 20px;
            width: 145px;
            &.toIndex {
                background: #0E0F2C;
                border-color: #0E0F2C;
            }
        }
    }
</style>
